home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_500 / wiconify / wiconify-source.lzh / Source / wIcon.c < prev    next >
C/C++ Source or Header  |  1991-04-19  |  20KB  |  698 lines

  1. /*
  2.  *  WICONIFY    A utility that allows you to iconify any Intuition window
  3.  *              on any screen, and to open WB windows on any screen.
  4.  *
  5.  *  wIcon.c     Handles most aspects of icon creation and maintenance
  6.  *
  7.  *  Copyright 1990 by Davide P. Cervone, all rights reserved.
  8.  *  You may use this code, provided this copyright notice is kept intact.
  9.  */
  10.  
  11. #define INTUITION_PREFERENCES_H             /* don't need 'em */
  12. #include <intuition/intuitionbase.h>
  13. #include "wHandler.h"
  14.  
  15. struct Window *WindowToActivate;        /* Activate this window on SELECTUP */
  16. static WSCREEN *Refresh;                /* List of screens to be refreshed */
  17.  
  18. #define ICONDELAY   2L      /* For window to come forward for CHANGEREFRESH */
  19. #define MAXWAIT     10      /* Number of attempts if it hasn't come forward */
  20. #define MOVE_DY     2048L   /* Distance to move screen when iconified */
  21.  
  22. #define WINDOW(layer)       ((struct Window *)((layer)->Window))
  23. #define LAYERREFRESHBITS    (LAYERSIMPLE | LAYERSMART)
  24. #define ICONSCREEN          ((WSCREEN *)theIcon->Window->UserData)
  25.  
  26.  
  27.  
  28. /*
  29.  *  SetRefresh()
  30.  *
  31.  *  Lock the layers of the window's screen
  32.  *  Change the window's refresh status
  33.  *  Get the window's layer
  34.  *  Change the layer's refresh status
  35.  *  Unlock the screen's layers
  36.  */
  37.  
  38. static void SetRefresh(theWindow,WindowBits)
  39. struct Window *theWindow;
  40. ULONG WindowBits;
  41. {
  42.    struct Layer *theLayer;
  43.    UWORD LayerBits = (WindowBits == SMART_REFRESH)? LAYERSMART: LAYERSIMPLE;
  44.  
  45.    Forbid();
  46.    LockLayerInfo(&theWindow->WScreen->LayerInfo);
  47.    theWindow->Flags = (theWindow->Flags & ~REFRESHBITS) | WindowBits;
  48.    theLayer = theWindow->WLayer;
  49.    theLayer->Flags = (theLayer->Flags & ~LAYERREFRESHBITS) | LayerBits;
  50.    UnlockLayerInfo(&theWindow->WScreen->LayerInfo);
  51.    Permit();
  52. }
  53.  
  54.  
  55. /*
  56.  *  SetBackdrop()
  57.  *
  58.  *  Lock the screen's layers
  59.  *  Add or remove the BACKDROP flag appropriately
  60.  *  Get the window's first layer (GZZ and requesters may give it more)
  61.  *  While there are more layers for this window (we assume they are sequential)
  62.  *    Set the backdrop status of the layer
  63.  *    Go on to the next layer
  64.  *  Start over again with the first layer behind the window
  65.  *  For any layers nbelowing to this window
  66.  *    Set the backdrop status of the layer
  67.  *    Move on to the previous layer
  68.  *  Unlock the layers
  69.  */
  70.  
  71. static void SetBackdrop(theWindow,Backdrop)
  72. struct Window *theWindow;
  73. int Backdrop;
  74. {
  75.    struct Layer *theLayer;
  76.  
  77.    Forbid();
  78.    LockLayerInfo(&theWindow->WScreen->LayerInfo);
  79.    if (Backdrop)
  80.       theWindow->Flags |=  BACKDROP;
  81.      else
  82.       theWindow->Flags &= ~BACKDROP;
  83.  
  84.    theLayer = theWindow->WLayer;
  85.    while (theLayer && theLayer->Window == (APTR)theWindow)
  86.    {
  87.       if (Backdrop)
  88.          theLayer->Flags |=  LAYERBACKDROP;
  89.         else
  90.          theLayer->Flags &= ~LAYERBACKDROP;
  91.        theLayer = theLayer->front;
  92.     }
  93.  
  94.    theLayer = theWindow->WLayer->back;
  95.    while (theLayer && theLayer->Window == (APTR)theWindow)
  96.    {
  97.       if (Backdrop)
  98.          theLayer->Flags |=  LAYERBACKDROP;
  99.         else
  100.          theLayer->Flags &= ~LAYERBACKDROP;
  101.       theLayer = theLayer->back;
  102.    }
  103.    UnlockLayerInfo(&theWindow->WScreen->LayerInfo);
  104.    Permit();
  105. }
  106.  
  107.  
  108. /*
  109.  *  TopWindow()
  110.  *
  111.  *  Lock the screen's layers so they don't change while we look
  112.  *  Start with the top-most layer
  113.  *  Look through the layer list for the first one with a window pointer
  114.  *  Get the layer's window pointer
  115.  *  Unlock the layers
  116.  *  Return the window.
  117.  */
  118.  
  119. static struct Window *TopWindow(theScreen)
  120. struct Screen *theScreen;
  121. {
  122.    struct Window *theWindow = NULL;
  123.    struct Layer_Info *theLayerInfo = &(theScreen->LayerInfo);
  124.    struct Layer *theLayer;
  125.    
  126.    LockLayers(theLayerInfo);
  127.    theLayer = theLayerInfo->top_layer;
  128.    while (theLayer && WINDOW(theLayer) == NULL) theLayer = theLayer->back;
  129.    if (theLayer) theWindow = WINDOW(theLayer);
  130.    UnlockLayers(theLayerInfo);
  131.    return(theWindow);
  132. }
  133.  
  134.  
  135. /*
  136.  *  HideWindow()
  137.  *
  138.  *  If the icon is a screen icon (not a window icon)
  139.  *    If the screen is the active one, activate the WB Iconify window
  140.  *    Send the screen to the back
  141.  *    Move the screen off the bottom of the display
  142.  *    Link the screen's icon into the WB screen list
  143.  *  Otherwise
  144.  *    If the icon is supposed to have its refresh status changed
  145.  *      If the window is a SMART_REFRESH one
  146.  *        Bring the window to the front
  147.  *        Wait for the window to come to the front (timeout after MAXWAIT)
  148.  *         (we must have the window completely uncovered before we change
  149.  *         the refresh status, otherwise the refresh regions get completely
  150.  *         messed up!)
  151.  *        Set the refresh type to SIMPLE_REFRESH
  152.  *        Mark the icon as changed
  153.  *    If the window is not already a backdrop window
  154.  *      Mark it as a backdrop window
  155.  *      Record the change so we can undo it later
  156.  *    If the window is getting refresh messages
  157.  *      Turn them off (dont update while we can't see it!)
  158.  *      Record the change
  159.  *    Finally, send the window to the back (behind the wIconify backdrop)
  160.  */
  161.  
  162. static void HideWindow(theIcon,Flags)
  163. WICONREF *theIcon;
  164. UWORD Flags;
  165. {
  166.    struct Window *theWindow = theIcon->Window;
  167.    short i = MAXWAIT;
  168.  
  169.    if (theIcon->Icon.Flags & WI_SCREENICON)
  170.    {
  171.       Forbid();
  172.       if (IntuitionBase->ActiveScreen == ICONSCREEN->Screen)
  173.          ActivateWindow(RealWB->BackDrop);
  174.       Permit();
  175.       ScreenToBack(ICONSCREEN->Screen);
  176.       MoveScreen(ICONSCREEN->Screen,0L,MOVE_DY);
  177.       LinkIcon(theIcon,RealWB);
  178.    } else {
  179.       if ((theIcon->Icon.Flags & WI_CHANGEREFRESH) || (Flags & WI_CHANGE))
  180.       {
  181.          if ((theWindow->Flags & REFRESHBITS) == SMART_REFRESH)
  182.          {
  183.             WindowToFront(theWindow);
  184.             while (theWindow != TopWindow(theIcon->Screen->Screen) && --i)
  185.                Delay(ICONDELAY);
  186.             SetRefresh(theWindow,SIMPLE_REFRESH);
  187.             theIcon->Icon.Flags |= WI_REFRESHCHANGE;
  188.          }
  189.       }
  190.       if ((theWindow->Flags & BACKDROP) == FALSE)
  191.       {
  192.          SetBackdrop(theWindow,TRUE);
  193.          theIcon->Icon.Flags |= WI_BACKDROPCHANGE;
  194.       }
  195.       if ((theWindow->Flags & NOCAREREFRESH) == FALSE)
  196.       {
  197.          theWindow->Flags |= NOCAREREFRESH;
  198.          theIcon->Icon.Flags |= WI_NOCARECHANGE;
  199.       }
  200.       WindowToBack(theWindow);
  201.    }
  202. }
  203.  
  204.  
  205. /*
  206.  *  ShowWindow()
  207.  *
  208.  *  If the icon is a screen icon
  209.  *    Move the screen back to its previous location
  210.  *    Bring it to the front
  211.  *  Otherwise
  212.  *    If the window was not a BACKDROP one before, fix its layers
  213.  *    If we changes the refresh report flag, reset it
  214.  *    Bring the window to the front
  215.  *    If we changed the refresh type of the window
  216.  *      Wait for the window to appear at the front (timeout after MAXWAIT)
  217.  *      Set the refresh type to SMART_REFRESH
  218.  *    Remove the flags that say what changes were made
  219.  */
  220.  
  221. static void ShowWindow(theIcon)
  222. WICONREF *theIcon;
  223. {
  224.    struct Window *theWindow = theIcon->Window;
  225.    short i = MAXWAIT;
  226.  
  227.    if (theIcon->Icon.Flags & WI_SCREENICON)
  228.    {
  229.       MoveScreen(ICONSCREEN->Screen,0L,-MOVE_DY);
  230.       ScreenToFront(ICONSCREEN->Screen);
  231.    } else {
  232.       if (theIcon->Icon.Flags & WI_BACKDROPCHANGE)
  233.          SetBackdrop(theWindow,FALSE);
  234.       if (theIcon->Icon.Flags & WI_NOCARECHANGE)
  235.          theWindow->Flags &= ~NOCAREREFRESH;
  236.       WindowToFront(theWindow);
  237.       if (theIcon->Icon.Flags & WI_REFRESHCHANGE)
  238.       {
  239.          while (theWindow != TopWindow(theIcon->Screen->Screen) && --i)
  240.             Delay(ICONDELAY);
  241.          SetRefresh(theWindow,SMART_REFRESH);
  242.       }
  243.       theIcon->Icon.Flags &= ~WI_CHANGEBITS;
  244.    }
  245. }
  246.  
  247.  
  248. /*
  249.  *  RefreshIcons()
  250.  *
  251.  *  If there is a screen to refresh
  252.  *    If we are supposed to clear the screen, mark it to be cleared
  253.  *    If the screen is not already in the list
  254.  *      Link it into the list and mark it as in the list
  255.  *  (The refreshing is delayed until after all the messages are processed
  256.  *  so we don't refresh the same screen multiple times)
  257.  */
  258.  
  259. void RefreshIcons(theScreen,ClearIt)
  260. WSCREEN *theScreen;
  261. int ClearIt;
  262. {
  263.    Forbid();
  264.    if (theScreen)
  265.    {
  266.       if (ClearIt) theScreen->Flags |= WI_CLEARIT;
  267.       if ((theScreen->Flags & WI_REFRESH) == FALSE)
  268.       {
  269.          theScreen->Flags |= WI_REFRESH;
  270.          theScreen->NextRefresh = Refresh;
  271.          Refresh = theScreen;
  272.       }
  273.    }
  274.    Permit();
  275. }
  276.  
  277.  
  278. /*
  279.  *  DrawGadgets()
  280.  *
  281.  *  Get the first gadget on the screen
  282.  *  While there are more gadgets
  283.  *    Temporarily use the MutualExclude flag as a backward pointer
  284.  *    Save the pointer to the last gadget seen
  285.  *    Go on to the next one
  286.  *  Start at the end of the list
  287.  *  While there are more gadgets to draw
  288.  *    Get the next gadget from MutualExclude (where we stored it above)
  289.  *    Reset MutualExclude to zero
  290.  *    Draw the given gadget
  291.  *  (The gadgets are drawn in reverse order to make them overlap correctly.
  292.  *  One could replace this routine by RefreshGadgets if desired.  There are
  293.  *  two reason's not to, however; RefreshGadgets draws all the gadgets first
  294.  *  then goes back and adds any select imagery or complements.  This causes
  295.  *  undue flickering of the icons if there are many of them selected.  Also,
  296.  *  if any selected ones overlap, the complementation cancels out on the
  297.  *  overlapped region)
  298.  */
  299.  
  300. static void DrawGadgets(theScreen)
  301. WSCREEN *theScreen;
  302. {
  303.    struct Gadget *theGadget = theScreen->BackDrop->FirstGadget;
  304.    struct Gadget *IconGadget = NULL;
  305.    
  306.    while (theGadget)
  307.    {
  308.       theGadget->MutualExclude = (LONG) IconGadget;
  309.       IconGadget = theGadget;
  310.       theGadget = theGadget->NextGadget;
  311.    }
  312.    while (IconGadget)
  313.    {
  314.       theGadget = IconGadget;
  315.       IconGadget = (struct Gadget *) theGadget->MutualExclude;
  316.       theGadget->MutualExclude = 0L;
  317.       RefreshGList(theGadget,theScreen->BackDrop,NULL,ONE);
  318.    }
  319. }
  320.  
  321.  
  322. /*
  323.  *  RefreshScreens()
  324.  *
  325.  *  For each screen in the list
  326.  *    If it still has a backdrop window (ie, the screen is not closing)
  327.  *      If we are supposed to clear the screen, do so
  328.  *      If the screen has gadgets, draw them
  329.  *    Clear the screen's refresh bits
  330.  *    Move on to the next screen
  331.  */
  332.  
  333. void RefreshScreens()
  334. {
  335.    Forbid();
  336.    while (Refresh)
  337.    {
  338.       if (Refresh->BackDrop)
  339.       {
  340.          if (Refresh->Flags & WI_CLEARIT) SetRast(Refresh->BackDrop->RPort,0L);
  341.          if (Refresh->BackDrop->FirstGadget) DrawGadgets(Refresh);
  342.       }
  343.       Refresh->Flags &= ~(WI_REFRESH| WI_CLEARIT);
  344.       Refresh = Refresh->NextRefresh;
  345.    }
  346.    Permit();
  347. }
  348.  
  349.  
  350. /*
  351.  *  UnLinkRefresh()
  352.  *
  353.  *  Find the given screen in the refresh list and remove it.
  354.  */
  355.  
  356. void UnLinkRefresh(theScreen)
  357. WSCREEN *theScreen;
  358. {
  359.    WSCREEN **ScreenPtr;
  360.  
  361.    Forbid();
  362.    ScreenPtr = &Refresh;
  363.    while (*ScreenPtr && *ScreenPtr != theScreen)
  364.       ScreenPtr = &((*ScreenPtr)->NextRefresh);
  365.    if (*ScreenPtr) *ScreenPtr = theScreen->NextRefresh;
  366.    Permit();
  367. }
  368.  
  369.  
  370. /*
  371.  *  RemoveIcon()
  372.  *
  373.  *  If the icon has a gadget
  374.  *    If the icon is selected
  375.  *      Unlink the gadget from the selection list
  376.  *      If this was the last icon on the screen update the menus
  377.  *      Mark the icon as not selected
  378.  *    If the screen still has a backdrop window
  379.  *      Remove the gadget from the window
  380.  *    Free the icon's gadget structure
  381.  *    Clear and refresh the screen's icons
  382.  */
  383.  
  384. void RemoveIcon(theIcon)
  385. WICONREF *theIcon;
  386. {
  387.    if (theIcon->Gadget)
  388.    {
  389.       if (theIcon->Icon.Flags & WI_SELECTED)
  390.       {
  391.          UnLinkGadget(theIcon->Gadget);
  392.          if (theIcon->Screen->Selected == NULL) UpdateActiveMenu();
  393.          theIcon->Icon.Flags &= ~WI_SELECTED;
  394.       }
  395.       if (theIcon->Screen->BackDrop)
  396.          RemoveGadget(theIcon->Screen->BackDrop,theIcon->Gadget);
  397.       FREESTRUCT(wGadget,theIcon->Gadget); theIcon->Gadget = NULL;
  398.       RefreshIcons(theIcon->Screen,TRUE);
  399.    }
  400. }
  401.  
  402.  
  403. /*
  404.  *  DeleteIcon()
  405.  *
  406.  *  Unlink the icon from the screen's list
  407.  *  Remove the icon gadget from the screen
  408.  *  If the screen has no more icons
  409.  *    If the screen has a task waiting to close it
  410.  *      Signal that task that it is now OK to close the screen
  411.  *    If Iconify is waiting to end, signal that it can try again
  412.  *    Update the menus (deactivate OPENALL, etc)
  413.  *  If the icon is not a screen icon (which is part of the scren structure)
  414.  *    Free the icon's memory
  415.  */
  416.  
  417. void DeleteIcon(theIcon)
  418. WICONREF *theIcon;
  419. {
  420.    UnLinkIcon(theIcon);
  421.    RemoveIcon(theIcon);
  422.    if (theIcon->Screen->IconRef == NULL)
  423.    {
  424.       if (theIcon->Screen->CloseTask)
  425.          Signal(theIcon->Screen->CloseTask,theIcon->Screen->CloseSignal);
  426.       if (EndSignal) Signal(IconTask,EndSignal);
  427.       UpdateActiveMenu();
  428.    }
  429.    if ((theIcon->Icon.Flags & WI_SCREENICON) == FALSE)
  430.       FREESTRUCT(wIconRef,theIcon);
  431. }
  432.  
  433.  
  434. /*
  435.  *  CloseIcon()
  436.  *
  437.  *  If the icon is allowed to be closed
  438.  *    If the icon wants to receive close messages, send one
  439.  *    Otherwise if the icon's window currently has a requester up, no nothing
  440.  *    Otherwise send the CLOSEWINDOW message to simulate pressing the
  441.  *      close gadget of the window
  442.  */
  443.  
  444. void CloseIcon(theIcon)
  445. WICONREF *theIcon;
  446. {
  447.    if ((theIcon->Icon.Flags & WI_NOCLOSE) == FALSE)
  448.    {
  449.       if (theIcon->Icon.Report & WI_REPORTCLOSE)
  450.          ReportEvent(WI_REPORTCLOSE,theIcon);
  451.       else if (theIcon->Window && theIcon->Window->FirstRequest) /* nothing */;
  452.       else SendIntuiMessage(CLOSEWINDOW,theIcon->Window);
  453.    }
  454. }
  455.  
  456.  
  457. /*
  458.  *  Iconify()
  459.  *
  460.  *  If we have an icon
  461.  *    If the icon is not already iconified, and it is allowed to be, and there
  462.  *        is somewhere to put the icon
  463.  *      If the icon is for a window or (if it IS a screen icon) if the
  464.  *          real WB screen is open and is not the screen whose icon this is
  465.  *        Find out it the icon's window is the active one
  466.  *        If so, activate the screen's backdrop window
  467.  *        Get a new gadget for the icon
  468.  *        If one was able to be allocated
  469.  *          Mark the icon as iconified
  470.  *          If the icon has an associated window
  471.  *            If it has no close gadget, mark the icon as not closable
  472.  *            Hide the window behind the wIconify backdrop window
  473.  *          Set up the gadget for the icon
  474.  *          Add the gadget to the backdrop window
  475.  *          Refresh the screen
  476.  *          If the icon wants iconification reports, send one
  477.  *          If the icon's window was the active one, activate its icon
  478.  */
  479.  
  480. void Iconify(theIcon,Flags)
  481. WICONREF *theIcon;
  482. UWORD Flags;
  483. {
  484.    int isActive;
  485.  
  486.    if (theIcon)
  487.    {
  488.       if ((theIcon->Icon.Flags & (WI_ICONIFIED| WI_NOICONIFY)) == FALSE &&
  489.            theIcon->Screen->BackDrop)
  490.       {
  491.          if ((theIcon->Icon.Flags & WI_SCREENICON) == FALSE ||
  492.              (RealWB && ICONSCREEN != RealWB))
  493.          {
  494.             isActive = (theIcon->Window == IntuitionBase->ActiveWindow);
  495.             if (isActive) ActivateWindow(theIcon->Screen->BackDrop), Delay(1L);
  496.             if (NEWSTRUCT(wGadget,theIcon->Gadget))
  497.             {
  498.                theIcon->Icon.Flags |= WI_ICONIFIED;
  499.                if (theIcon->Window)
  500.                {
  501.                   if ((theIcon->Window->IDCMPFlags & CLOSEWINDOW) == FALSE)
  502.                      theIcon->Icon.Flags |= WI_NOCLOSE;
  503.                   HideWindow(theIcon,Flags);
  504.                }
  505.                SetupGadget(theIcon);
  506.                AddGadget(theIcon->Screen->BackDrop,theIcon->Gadget,0);
  507.                RefreshIcons(theIcon->Screen,TRUE);
  508.                Forbid();
  509.                if (theIcon->Icon.Report & WI_REPORTICONIFIED)
  510.                   ReportEvent(WI_REPORTICONIFIED,theIcon);
  511.                if (isActive) SelectIcon(theIcon,FALSE);
  512.                Permit();
  513.             }
  514.          }
  515.       }
  516.    }
  517. }
  518.  
  519.  
  520. /*
  521.  *  Restore()
  522.  *
  523.  *  If we have an icon to restore
  524.  *    If it is iconified
  525.  *      If the icon wants restores reported, report it
  526.  *      Otherwise
  527.  *        If the icon has a window
  528.  *          Bring it out from behind the backdrop window
  529.  *          If we are to activate the window right away, do so
  530.  *          Otherwise record it for later activation
  531.  *        If we are not saving the icon's position, clear its position
  532.  *        Otherwise save the icon's position
  533.  *        If we are reporting restoration events, do so
  534.  *        If the icon is a screen icon
  535.  *          Remove the icon from the WB screen and reset its screen pointer
  536.  *        Otherwise if the icon has a window remove the icon from the screen
  537.  *        (don't remove icons with no windows - they must call DeleteIcon)
  538.  */
  539.  
  540. void Restore(theIcon,ActivateNow)
  541. WICONREF *theIcon;
  542. int ActivateNow;
  543. {
  544.    if (theIcon)
  545.    {
  546.       if (theIcon->Icon.Flags & WI_ICONIFIED)
  547.       {
  548.          if (theIcon->Icon.Report & WI_REPORTOPEN)
  549.          {
  550.             ReportEvent(WI_REPORTOPEN,theIcon);
  551.          } else {
  552.             if (theIcon->Window)
  553.             {
  554.                ShowWindow(theIcon);
  555.                if (ActivateNow) ActivateWindow(theIcon->Window);
  556.                  else WindowToActivate = theIcon->Window;
  557.                theIcon->Icon.Flags &= ~WI_ICONIFIED;
  558.             }
  559.             if (theIcon->Icon.Flags & WI_NOSAVEPOS)
  560.             {
  561.                theIcon->Icon.x = theIcon->Icon.y = 0;
  562.             } else {
  563.                theIcon->Icon.x = theIcon->Gadget->Gadget.LeftEdge;
  564.                theIcon->Icon.y = theIcon->Gadget->Gadget.TopEdge;
  565.             }
  566.             if (theIcon->Icon.Report & WI_REPORTRESTORE)
  567.                ReportEvent(WI_REPORTRESTORE,theIcon);
  568.             if (theIcon->Icon.Flags & WI_SCREENICON)
  569.             {
  570.                DeleteIcon(theIcon);
  571.                theIcon->Screen = ICONSCREEN; 
  572.             } else if (theIcon->Window) RemoveIcon(theIcon);
  573.          }
  574.       }
  575.    }
  576. }
  577.  
  578.  
  579. /*
  580.  *  OpenAllIcons()
  581.  *
  582.  *  If a screen was specified
  583.  *    Get the first icon on the screen
  584.  *    While there are more icons to handle
  585.  *      Restore the icon and go on
  586.  *      (we save the pointer to the next icon first since Restore may
  587.  *      free the icon's memory and invalidate the pointer)
  588.  */
  589.  
  590. void OpenAllIcons(theScreen)
  591. WSCREEN *theScreen;
  592. {
  593.    WICONREF *theIcon,*nextIcon;
  594.  
  595.    if (theScreen)
  596.    {
  597.       theIcon = theScreen->IconRef;
  598.       while (theIcon)
  599.       {
  600.          nextIcon = theIcon->Next;
  601.          Restore(theIcon,TRUE);
  602.          theIcon = nextIcon;
  603.       }
  604.    }
  605. }
  606.  
  607.  
  608. /*
  609.  *  OpenSelected()
  610.  *
  611.  *  If there is a screen to work with
  612.  *    Get the first gadget selected on the screen
  613.  *    While there are more gadgets to handle
  614.  *      Restore the window associated with gadget
  615.  *      Go on to the next one
  616.  *      (we save the pointer to the next gadget before restoring since
  617.  *      Restore() will remove the gadget before it returns)
  618.  */
  619.  
  620. void OpenSelected(theScreen,Activate)
  621. WSCREEN *theScreen;
  622. int Activate;
  623. {
  624.    struct wGadget *theGadget,*nextGadget;
  625.  
  626.    if (theScreen)
  627.    {
  628.       theGadget = theScreen->Selected;
  629.       while (theGadget)
  630.       {
  631.          nextGadget = theGadget->NextSelect;
  632.          Restore(theGadget->Gadget.UserData,Activate);
  633.          theGadget = nextGadget;
  634.       }
  635.    }
  636. }
  637.  
  638.  
  639. /*
  640.  *  CloseSelected()
  641.  *
  642.  *  Start with the first selected gadget on the screen
  643.  *  While there are more gadgets to handle
  644.  *    Close the icon associated with the gadget
  645.  *    Go on to the next gadget
  646.  */
  647.  
  648. void CloseSelected(theScreen)
  649. WSCREEN *theScreen;
  650. {
  651.    struct wGadget *theGadget = theScreen->Selected;
  652.    struct wGadget *nextGadget;
  653.    
  654.    Forbid();
  655.    while (theGadget)
  656.    {
  657.       nextGadget = theGadget->NextSelect;
  658.       CloseIcon(GADGETICON);
  659.       theGadget = nextGadget;
  660.    }
  661.    Permit();
  662. }
  663.  
  664.  
  665. /*
  666.  *  LockSelected()
  667.  *
  668.  *  Start with the first selected gadget on the screen
  669.  *  Look through the list to see if any are locked
  670.  *  (if they are all locked, LockIt will remain FALSE, else it will be TRUE)
  671.  *  For each selected gadget on the screen
  672.  *    Set the LOCKED flag appropriately
  673.  */
  674.  
  675. void LockSelected(theScreen)
  676. WSCREEN *theScreen;
  677. {
  678.    struct wGadget *theGadget = theScreen->Selected;
  679.    int LockIt = FALSE;
  680.    
  681.    Forbid();
  682.    while (theGadget && !LockIt)
  683.    {
  684.       LockIt = ((GADGETICON->Icon.Flags & WI_LOCKED) == FALSE);
  685.       theGadget=theGadget->NextSelect;
  686.    }
  687.  
  688.   for (theGadget = theScreen->Selected; theGadget;
  689.         theGadget = theGadget->NextSelect)
  690.    {
  691.       if (LockIt)
  692.          GADGETICON->Icon.Flags |=  WI_LOCKED;
  693.         else
  694.          GADGETICON->Icon.Flags &= ~WI_LOCKED;
  695.    }
  696.    Permit();
  697. }
  698.